package com.minimalist.lindi.mapper;

import com.minimalist.common.entity.lindi.po.LindiTradeApplicationApproveFile;
import com.minimalist.common.entity.lindi.vo.tradeapplicationapprovefile.LindiTradeApplicationApproveFileVO;
import com.minimalist.common.entity.lindi.vo.tradeapplicationapprovefile.TradeApplicationApproveFileQueryVO;
import com.mybatisflex.core.BaseMapper;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryChain;
import com.mybatisflex.core.query.QueryWrapper;

/**
 * 林地指标交易平台_交易申请审批文件 映射层。
 *
 * @author 11987
 * @since 2025-06-07
 */
public interface LindiTradeApplicationApproveFileMapper extends BaseMapper<LindiTradeApplicationApproveFile>{

    /**
     * 根据审批文件ID查询交易申请审批文件
     *
     * @param approveFileId 审批文件ID
     * @return 交易申请审批文件
     */
    default LindiTradeApplicationApproveFile selectTradeApplicationApproveFileByApproveFileId(Long approveFileId){
        return selectOneByQuery(QueryChain.create().eq(LindiTradeApplicationApproveFile::getApproveFileId, approveFileId));
    }

    /**
     * 根据审批文件ID查询交易申请审批文件VO
     *
     * @param approveFileId 审批文件ID
     * @return 交易申请审批文件VO
     */
    default LindiTradeApplicationApproveFileVO getTradeApplicationApproveFileByApproveFileId(Long approveFileId){
        return selectOneByQueryAs(QueryChain.create().eq(LindiTradeApplicationApproveFile::getApproveFileId, approveFileId), LindiTradeApplicationApproveFileVO.class);
    }

    /**
     * 分页查询交易申请审批文件列表
     *
     * @param page    分页对象
     * @param queryVO 查询条件
     * @return 分页结果
     */
    default Page<LindiTradeApplicationApproveFileVO> getPageTradeApplicationApproveFileList(Page<LindiTradeApplicationApproveFileVO> page, TradeApplicationApproveFileQueryVO queryVO){
        return paginateAs(page,
                QueryWrapper.create()
                        .eq(LindiTradeApplicationApproveFile::getTradeApplicationId, queryVO.getTradeApplicationId())
                        .like(LindiTradeApplicationApproveFile::getApproveFileName, queryVO.getApproveFileName())
                        .orderBy(LindiTradeApplicationApproveFile::getCreateTime, false),
                LindiTradeApplicationApproveFileVO.class);
    }
}
